package com.van.bo.badwrting.edit.domain;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;


/**
 * 储存数据
 */
@Document(indexName = "java_data_2")
@JsonIgnoreProperties(ignoreUnknown = true)
public class JavaDataInES {

    public static final String TIME_PATTERN = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis";
    @Id
    private String id;//es的ID
    @Field(type = FieldType.Text)
    private String data = "";//问题
    @Field(type = FieldType.Text)
    private String desc = "";//答案和描述

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime = new Date();//创建时间

    @Field(type = FieldType.Keyword, format = DateFormat.custom, pattern = TIME_PATTERN)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime = new Date();//修改时间

    @Field(type = FieldType.Text)
    private String other = "";//备注字段


    @Transient
    private long dataVersion;

    public String getData() {
        return StringUtils.trim(data);
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getDesc() {
        return StringUtils.trim(desc);
    }
    public String getSubDesc() {
        if (StringUtils.isNotBlank(desc) && desc.length()>301){
            return desc.substring(0,300)+"。。。";
        }
        return StringUtils.trim(desc);
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getOther() {
        return StringUtils.trim(other);
    }

    public void setOther(String other) {
        this.other = other;
    }

    public long getDataVersion() {
        return dataVersion;
    }

    public void setDataVersion(long dataVersion) {
        this.dataVersion = dataVersion;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
